package main

import "fmt"

func main() {
	//创建切片
	s := make([]int, 0)
	//添加数据
	s1 := append(s, 10, 20, 30, 40, 450, 40, 70, 8, 9, 7, 9, 7, 6, 4, 6, 4, 3, 4, 6, 46)
	fmt.Println(s1)
	fmt.Println(cap(s1))
	//截取
	s2 := s1[:8]
	fmt.Println("s2", s2)
	fmt.Println(len(s2))
	fmt.Println(cap(s2))
	//修改切片，会把最开始的切片一并修改
	s2[3] = 999
	fmt.Println(s2)
	fmt.Println(s1)
	//打印地址
	fmt.Printf("%p\n", s2)
	//切片的复制
	s3 := append(s, 10, 20, 30, 40, 450, 40, 70, 8, 9, 7, 9, 7, 6, 4, 6, 4, 3, 4, 6, 46)
	s4 := make([]int, 20)
	copy(s4, s3)
	fmt.Println(s4)
	//地址不同，也可复制
	fmt.Printf("%p\n", s4)
	fmt.Printf("%p\n", s3)
}
